let English = /[a-zA-Z]+/
window.onload = function(e){
    fetch(config.language[lang].url)
        .then(d=>d.json())
        .then(d=>{load_info(d)})
    
    let language = config.language
    let lang_dom = document.getElementById('language')
    let list_lang = Object.keys(language)
    for(let i=0; i<list_lang.length; i++)
    {
        let node = document.createElement('span')
        node.innerHTML = English.test(list_lang[i])? list_lang[i].toUpperCase() : list_lang[i]
        if(i+1<list_lang.length)
            node.innerHTML += " | "
        node.onclick = ()=>setLanguage(list_lang[i])
        lang_dom.appendChild(node)
    }
}   

function setLanguage(lang){
    localStorage.setItem("lang", lang)
    location.reload()
}

function load_info(data)
{
    for(let k in data)
    {
        let dom = document.getElementById('my_'+k)
        let d = data[k]
        if(k == 'org')
        {
            for(let i=0; i<d.length; i++)
            {
                let node = document.createElement('a')
                node.href = d[i].url
                node.innerHTML = d[i].name
                dom.appendChild(node)
                if(d.length > 1 && i+1<d.length)
                {
                    node = document.createElement("span")
                    node.innerHTML = ', '
                    dom.appendChild(node)
                }
            }
        }
        else dom.innerHTML = d
    }
}